<template>
  <div class="shopcart">
    <div class="content">
      <div class="content-left" @click="toShopCartList">
        <i class="iconfont icon-gouwuche gouwuche" :class="{highlight: totalCount > 0}"></i>
        <div class="num" v-show="totalCount > 0">{{ totalCount }}</div>
      </div>
      <div class="content-right">
        <div class="totalPrice">&yen; {{ totalPrice }}</div>
        <div class="toPay">
          去支付<i class="iconfont icon-xiangyoujiantou"></i>
        </div>
      </div>
      <!-- 动画小球容器 -->
      <div class="ball-container">
        <Transition @before-enter="beforeDrop" @enter="dropping" @after-enter="afterDrop">
          <div class="ball" v-show="ball.showorhidden">
            <div class="inner"></div>
          </div>
        </Transition>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import ShopCartClass from "../service/shopcart"
const {
  refreshShopCartList,
  ball,
  beforeDrop,
  dropping,
  afterDrop,
  toShopCartList,
} = ShopCartClass

// 获取购物车图书总数量 + 购物车总价格
const { totalCount, totalPrice } = refreshShopCartList()
</script>

<style lang="scss" scoped>
.shopcart {
  position: fixed;
  left: 0;
  bottom: 0;
  width: 100%;
  background-color: #fff;
  .content {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 0.73rem;
    column-gap: 0.3rem;
    &-left {
      width: 1.095rem;
      height: 0.53rem;
      position: relative;
      .gouwuche {
        font-size: 0.4rem;
        &.highlight {
          color: black;
        }
      }
      .num {
        position: absolute;
        left: 0.3rem;
        top: -0.1rem;
        color: #fff;
        background-color: red;
        font-size: 0.18rem;
        padding: 0 0.02rem;
        border-radius: 0.1rem;
        width: 0.3rem;
        text-align: center;
      }
    }
    &-right {
      display: flex;
      align-items: center;
      justify-content: center;
      border-radius: 1rem;
      width: 3.5rem;
      height: 0.53rem;
      font-size: 0.29rem;
      background-color: #ffd102;
      color: black;
      column-gap: 0.05rem;
      .totalPrice {
        font-weight: bold;
      }
      .toPay {
        font-size: 0.21rem;
      }
    }
    /* 小球动画 */
    .ball-container {
      .ball {
        position: fixed;
        width: .16rem;
        height: .16rem;
        left: .35rem;
        bottom: .22rem;
        /* 
          生成贝塞尔曲线 https://cubic-bezier.com/
          父元素的Y轴(垂直)位移，即贝塞尔曲线
        */
        transition: all .4s cubic-bezier(0.48, -0.35, 0.78, 0.45);
        .inner {
          width: .16rem;
          height: .16rem;
          border-radius: 50%;
          background-color: #1985f1;
          /* 子元素X轴(水平)位移，以与父元素的位移协调,即可实现抛物线效果 */
          transition: all .4s linear;
        }
      }
    }
  }
}
</style>
